#pragma once

#include "Particle.h"
#include "RecyclingArray.h"

#define NUMPARTICLES 1111

class ParticleEmitter
{
public:
	ParticleEmitter();
	virtual ~ParticleEmitter();

	virtual void Update(float fTimeDelta);

	virtual HRESULT Render( const D3DXMATRIX& matView, const D3DXMATRIX& matVP );

	virtual HRESULT RestoreDeviceObjects(const char *strTextureFilename);

	virtual void InvalidateDeviceObjects();

	static void SetRenderStates();
	static void ResetRenderStates();

	// attributes
	D3DXVECTOR3 GetGravity(void) const { return(m_vGravity); }
	void SetGravity(const D3DXVECTOR3 &data) { m_vGravity = data; }

	D3DXVECTOR3 GetPos(void) const { return(m_vPos); }
	void SetPos(const D3DXVECTOR3 &data) { m_vPos = data; }

	float GetMinEmitRate(void) const { return(m_fMinEmitRate); }
	void SetMinEmitRate(const float data) { m_fMinEmitRate = data; }

	float GetMaxEmitRate(void) const { return(m_fMaxEmitRate); }
	void SetMaxEmitRate(const float data) { m_fMaxEmitRate = data; }

	float GetMinSize(void) const { return(m_fMinSize); }
	void SetMinSize(const float data) { m_fMinSize = data; }

	float GetMaxSize(void) const { return(m_fMaxSize); }
	void SetMaxSize(const float data) { m_fMaxSize = data; }

	float GetMinLife(void) const { return(m_fMinLife); }
	void SetMinLife(const float data) { m_fMinLife = data; }

	float GetMaxLife(void) const { return(m_fMaxLife); }
	void SetMaxLife(const float data) { m_fMaxLife = data; }

	D3DXVECTOR3 GetSpawnDir1(void) const { return(m_vSpawnDir1); }
	void SetSpawnDir1(const D3DXVECTOR3 &data) { m_vSpawnDir1 = data; }

	D3DXVECTOR3 GetSpawnDir2(void) const { return(m_vSpawnDir2); }
	void SetSpawnDir2(const D3DXVECTOR3 &data) { m_vSpawnDir2 = data; }

	D3DXCOLOR GetColor1(void) const { return(m_Color1); }
	void SetColor1(const D3DXCOLOR &data) { m_Color1 = data; }

	D3DXCOLOR GetColor2(void) const { return(m_Color2); }
	void SetColor2(const D3DXCOLOR &data) { m_Color2 = data; }

	int GetVBSize(void) const { return(m_iVBSize); }
	void SetVBSize(const int data) { m_iVBSize = data; }

private:

	// particle system attributes
	D3DXVECTOR3 m_vGravity;
	D3DXVECTOR3 m_vPos; // position of emitter
	float m_fMinEmitRate; // in particles/sec
	float m_fMaxEmitRate; // in particles/sec

	// these vars determine starting values for each particle

	float m_fMinSize;
	float m_fMaxSize;

	float m_fMinLife;
	float m_fMaxLife;


	D3DXVECTOR3 m_vSpawnDir1;
	D3DXVECTOR3 m_vSpawnDir2;

	D3DXCOLOR m_Color1;
	D3DXCOLOR m_Color2;
	
	// other stuff
	float m_fNumNewPartsExcess;
	int m_iVBSize; // size of the vertex buffer (can and should be less than NUMPARTICLES)
	LPDIRECT3DVERTEXBUFFER9 m_vbParticles;
	LPDIRECT3DINDEXBUFFER9 m_ibParticles;
	LPDIRECT3DTEXTURE9 m_texParticle;

	CRecyclingArray<Particle, NUMPARTICLES> m_Particles;
};

